#include "SeqList.h"

#define TEST_HEADER printf("\n**********************%s**********************\n",__FUNCTION__)

void TestInit()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    printf("初始化后:head.size expect 0,actual %lu\n",head.size);
}
void TestPushBack()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    SeqListPushBack(&head,'g');
    SeqListPushBack(&head,'f');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'a');

    PrintChar(&head,"进行尾插7个元素");
}
void TestPopBack()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    SeqListPushBack(&head,'g');
    SeqListPushBack(&head,'f');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'a');

    PrintChar(&head,"进行尾插7个元素");
    SeqListPopBack(&head);
    SeqListPopBack(&head);
    SeqListPopBack(&head);
    PrintChar(&head,"进行删除3个元素");
    SeqListPopBack(&head);
    SeqListPopBack(&head);
    SeqListPopBack(&head);
    SeqListPopBack(&head);
    PrintChar(&head,"进行删4个元素");

    SeqListPopBack(&head);
    PrintChar(&head,"尝试对空顺序表进行删除");
}
void TestPushFront()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    SeqListPushFront(&head,'a');
    SeqListPushFront(&head,'b');
    SeqListPushFront(&head,'c');
    SeqListPushFront(&head,'d');
    SeqListPushFront(&head,'e');
    SeqListPushFront(&head,'f');
    SeqListPushFront(&head,'g');
    PrintChar(&head,"进行头插7个元素");
}
void TestPopFront()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    SeqListPushFront(&head,'a');
    SeqListPushFront(&head,'b');
    SeqListPushFront(&head,'c');
    SeqListPushFront(&head,'d');
    SeqListPushFront(&head,'e');
    SeqListPushFront(&head,'f');
    SeqListPushFront(&head,'g');
    PrintChar(&head,"进行头插7个元素");

    SeqListPopFront(&head);
    SeqListPopFront(&head);
    SeqListPopFront(&head);
    PrintChar(&head,"进行头删3个元素");
    SeqListPopFront(&head);
    SeqListPopFront(&head);
    SeqListPopFront(&head);
    SeqListPopFront(&head);
    PrintChar(&head,"进行头删4个元素");
    SeqListPopFront(&head);
    PrintChar(&head,"尝试对空顺序表进行删除");
}
void TestGet()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    int ret=0;
    SeqListType tmp='\0';
    ret=SeqListGet(&head,3,&tmp);
    printf("尝试对空顺序表获取元素：ret expect 0,actual %d\n",ret);
    SeqListPushBack(&head,'g');
    SeqListPushBack(&head,'f');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'a');

    PrintChar(&head,"进行尾插7个元素");
    ret=SeqListGet(&head,3,&tmp);
    printf("获取顺序表中下标为3的元素：ret expect 1,actual %d,tmp expect d,actual %c\n",ret,tmp);
    ret=SeqListGet(&head,6,&tmp);
    printf("获取顺序表中下标为6的元素：ret expect 1,actual %d,tmp expect a,actual %c\n",ret,tmp);

    ret=SeqListGet(&head,12,&tmp);
    printf("尝试获取非法位置元素：ret expect 0,actual %d\n",ret);
}
void TestSet()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    SeqListSet(&head,13,'z');
    PrintChar(&head,"尝试对空顺序表进行设置\n");
    SeqListPushBack(&head,'g');
    SeqListPushBack(&head,'f');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'a');

    PrintChar(&head,"进行尾插7个元素");
    SeqListSet(&head,3,'m');
    PrintChar(&head,"将下标为3位置元素进行设置为m\n");
    SeqListSet(&head,6,'z');
    PrintChar(&head,"将下标为6位置元素进行设置为z\n");
    SeqListSet(&head,13,'z');
    PrintChar(&head,"尝试设置非法位置\n");
}
 void TestFind()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    size_t find=0;
    find=SeqListFind(&head,'z');
    printf("对空顺序表进行查找： find expect %lu,actual %lu\n",(size_t)-1,find);
    SeqListPushBack(&head,'g');
    SeqListPushBack(&head,'f');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'a');

    PrintChar(&head,"进行尾插7个元素");
    find=SeqListFind(&head,'d');
    printf("对顺序表进行查找元素d： find expect 3,actual %lu\n",find);
    find=SeqListFind(&head,'a');
    printf("对顺序表进行查找元素a： find expect 6,actual %lu\n",find);
    find=SeqListFind(&head,'z');
    printf("对顺序表进行查找不存在的元素： find expect %lu,actual %lu\n",(size_t)-1,find);
}
void TestInsert()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    SeqListInsert(&head,0,'g');
    PrintChar(&head,"对空顺序表进行插入");
    SeqListPushBack(&head,'f');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'a');

    PrintChar(&head,"进行尾插6个元素");
    SeqListInsert(&head,0,'z');
    PrintChar(&head,"对顺序下标为0位置进行插入z");
    SeqListInsert(&head,3,'m');
    PrintChar(&head,"对顺序表下标为3位置进行插入m");
    SeqListInsert(&head,13,'p');
    PrintChar(&head,"尝试对非法位置进行插入");
}
void TestErase()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    SeqListErase(&head,2);
    PrintChar(&head,"尝试对空顺序表进行删除");
    SeqListPushBack(&head,'g');
    SeqListPushBack(&head,'f');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'a');

    PrintChar(&head,"进行尾插7个元素");
    SeqListErase(&head,2);
    PrintChar(&head,"对顺序表进行删除下标为2位置的值");
    SeqListErase(&head,6);
    PrintChar(&head,"对顺序表进行删除下标为4位置的值");
    SeqListErase(&head,14);
    PrintChar(&head,"尝试对非法位置进行删除");

}
void TestRemove()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    SeqListRemove(&head,'a');
    PrintChar(&head,"尝试对空顺序表进行删除");
    SeqListPushBack(&head,'g');
    SeqListPushBack(&head,'f');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'a');

    PrintChar(&head,"进行尾插7个元素");
    SeqListRemove(&head,'a');
    PrintChar(&head,"删除顺序表中元素a");
    SeqListRemove(&head,'d');
    PrintChar(&head,"删除顺序表中元素d");
    SeqListRemove(&head,'z');
    PrintChar(&head,"尝试删除不存在的元素z");
}
void TestRemoveAll()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    SeqListRemoveAll(&head,'a');
    PrintChar(&head,"尝试对空顺序表进行删除");
    SeqListPushBack(&head,'g');
    SeqListPushBack(&head,'a');
    SeqListPushBack(&head,'f');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'a');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'a');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'a');
    SeqListPushBack(&head,'c');

    PrintChar(&head,"进行尾插14个元素");
    SeqListRemoveAll(&head,'a');
    PrintChar(&head,"删除顺序表中所有的元素a");
    SeqListRemoveAll(&head,'c');
    PrintChar(&head,"删除顺序表中所有的元素c");
    SeqListRemoveAll(&head,'m');
    PrintChar(&head,"尝试删除不存在的元素");
}
void TestGetSize()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    size_t size=0;
    size=SeqListGetSize(&head);
    printf("对空顺序表进行求size :expect 0,actual %lu\n",size);
    SeqListPushBack(&head,'g');
    SeqListPushBack(&head,'f');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'a');
    PrintChar(&head,"进行尾插7个元素");
    size=SeqListGetSize(&head);
    printf("求顺序表的size:expect 7,actual %lu\n",size);
}
void TestEmpty()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    int ret=0;
    ret=SeqListEmpty(&head);
    printf("对空顺序表进行判空ret :expect 1,actual %d\n",ret);
    SeqListPushBack(&head,'g');
    SeqListPushBack(&head,'f');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'a');

    PrintChar(&head,"进行尾插7个元素");
    ret=SeqListEmpty(&head);
    printf("对非空顺序表进行判空ret :expect 0,actual %d\n",ret);
}
void TestSeqListBubbleSort()
{
    TEST_HEADER;
    SeqList head;
    SeqListInit(&head);
    SeqListPushBack(&head,'g');
    SeqListPushBack(&head,'b');
    SeqListPushBack(&head,'e');
    SeqListPushBack(&head,'c');
    SeqListPushBack(&head,'a');
    SeqListPushBack(&head,'d');
    SeqListPushBack(&head,'f');

    PrintChar(&head,"进行尾插7个元素");
    SeqListBubbleSort(&head);
    PrintChar(&head,"进行冒泡排序后");
}
int main()
{
    TestInit();
    TestPushBack();
    TestPopBack();
    TestPushFront();
    TestPopFront();
    TestGet();
    TestSet();
    TestFind();
    TestInsert();
    TestErase();
    TestRemove();
    TestRemoveAll();
    TestGetSize();
    TestEmpty();
    TestSeqListBubbleSort();
    return 0;
}
